package com.example.demo.collerct;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.entity.Blog;
import com.example.demo.entity.Tag;
import com.example.demo.service.Blogservice;
import com.example.demo.service.Tagservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class Tagcollerct {
    @Autowired
    Tagservice tagservice;
    @Autowired
    Blogservice blogservice;
    @RequestMapping("/toTageaka")
    public String asas(Model model, @RequestParam(defaultValue = "1")Integer pageIndex){
        Page<Tag> page = new Page(pageIndex,3);
        model.addAttribute("page", tagservice.selectBy(page));
        return "admin/tags";
    }
    @RequestMapping("/toinsertTag")
    public String ask(){
        return "admin/tags-input";
    }

    @RequestMapping("/insertTag")
    public String aska(Model model,Tag tag){
        int insert = tagservice.insert(tag);
        System.out.println(insert);
        return "forward:toTageaka";
    }

    @RequestMapping("/toUpdateTag")
    public String askaq(Model model,int id){
        Tag tag = tagservice.selectAka(id);
        model.addAttribute("tag",tag);
        return "admin/tags-input";
    }
    @RequestMapping("/UpdateTag")
    public String askaqa(Model model,Tag tag){
        int update = tagservice.update(tag);
        System.out.println(update);
        return "forward:toTageaka";
    }
    @ResponseBody
    @RequestMapping("/deleteTo")
    public Object qwerty(int id){
        Map<String,String> map = new HashMap<>();
        int blog = blogservice.TagselectByia(id);
        if (blog==0){
            int date = tagservice.date(id);
        }else {
            map.put("msg","没有");
        }
        return map;
    }
}
